哈囉呀 ~ 大家好呀 ~ 今天又要繼續來修練我們 C# 的語法啦 ! 今天來點 C# 中超好用的函數工具喔,一起加油吧 !
string s = "i,t,h,o,m,e";
string[] array = s.Split(',');
foreach (var item in array)
{
Console.WriteLine(item);
}
i
t
h
o
m
e
string s = "ithome magic";
string r = s.Replace("magic", "魔法");
Console.WriteLine(r);
ithome 魔法
string s = "ithome";
string sub = s.Substring(3);
Console.WriteLine(sub);
ome
string s = "ithome";
if (s.Contains("it"))
{
Console.WriteLine("ithome 裡面包含了 it");
}
ithome 裡面包含了 it
try
{
string[] array = { "0", "1", "2" };
Console.WriteLine(array[3]);
}
catch (IndexOutOfRangeException ex)
{
Console.WriteLine(ex.ToString()); //把ex印出來
}
System.IndexOutOfRangeException: Index was outside the bounds of the array.
int[,] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write(matrix[i, j] + " ");
}
Console.WriteLine();
}
1 2 3
4 5 6
7 8 9
太好了 ~ 終於把 C# 常用的一些語法說完了,下一篇就要開始介紹關於 C# 的物件與類別,那今天就到這裡囉 ~ 掰掰啦 ズイ₍₍ (ง ˘ω˘ )ว ⁾⁾ ⁽⁽ 〪ɾ( ˘ω˘ 〫ɩ ) ₎₎ズイ
https://learn.microsoft.com/zh-tw/dotnet/csharp/
https://ithelp.ithome.com.tw/articles/10220898
https://www.youtube.com/watch?v=T9BeejD3i0g